package com.vf.admin.client.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.vf.admin.client.dao.SystemAlertDao;
import com.vf.admin.client.service.AppUserService;
import com.vf.admin.client.service.SystemAlertService;
import com.vf.admin.client.tx.utils.TxIm;
import com.vf.admin.miaodong.entity.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class SystemAlertServiceImpl implements SystemAlertService {

    @Autowired
    private SystemAlertDao systemAlertDao;
    @Autowired
    private AppUserService appUserService;

    /**
     * 亲密度降低通知
     * @param toTengXunCode
     * @param nick
     * @param intimacy
     */
    @Override
    public void sendQMT_DOWN(Integer toTengXunCode, String nick, String intimacy) {
        String kry = "QMD_DOWN";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, nick, intimacy);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    /**
     * 别人查看了你通知
     * @param toTengXunCode
     * @param nick
     */
    @Override
    public void sendML_LOOK_T_INFO(Integer toTengXunCode, String nick) {
        String kry = "ML_LOOK_T_INFO";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, nick);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
            TxIm.sendSystemAlert(toTengXunCode, "开通贵族|享文字免费畅聊");
        }
    }

    /**
     * 获得新粉丝通知
     * @param toTengXunCode
     * @param nick
     */
    @Override
    public void sendNEW_FANS(Integer toTengXunCode, String nick) {
        String kry = "NEW_FANS";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, nick);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    /**
     * 家族新消息通知
     * @param toTengXunCode
     */
    @Override
    public void familyNEWS(Integer toTengXunCode) {
        String kry = "FAMILY_NEWS";
        String content = systemAlertDao.getByKey(kry).getContent();
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void authNEWS(Integer toTengXunCode, String authName, String reason) {
        String kry = "AUTH_REJECT";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, authName, reason);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void withdrawApply(Integer toTengXunCode) {
        String kry = "WITHDRAW_APPLY";
        String content = systemAlertDao.getByKey(kry).getContent();
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void withdrawSuccess(Integer toTengXunCode) {
        String kry = "WITHDRAW_SUCCESS";
        String content = systemAlertDao.getByKey(kry).getContent();
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void withdrawReject(Integer toTengXunCode, String reason) {
        String kry = "WITHDRAW_REJECT";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, reason);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void commendDynamic(Integer toTengXunCode, String nick) {
        String kry = "COMMEND_DYNAMIC";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, nick);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void parseDynamic(Integer toTengXunCode, String nick) {
        String kry = "PARSE_DYNAMIC";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, nick);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void guard(Integer toTengXunCode, String nick) {
        String kry = "GUARD";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, nick);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void giveGift(Integer toTengXunCode, String nick, String giftName, BigDecimal meili, BigDecimal goldCoin) {
        String kry = "GIVE_GIFT";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, nick, giftName, meili, goldCoin);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void hello(Integer toTengXunCode) {
        String kry = "HELLO";
        String content = systemAlertDao.getByKey(kry).getContent();
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }

    @Override
    public void joinFamily(Integer toTengXunCode, String familyName) {
        String kry = "JOIN_FAMILY";
        String content = systemAlertDao.getByKey(kry).getContent();
        content = String.format(content, familyName);
        AppUser appUser = appUserService.getTengxuncodeByUser(toTengXunCode);
        if(ObjectUtil.isNotNull(appUser) && ObjectUtil.equal(1, appUser.getIsReal())){
            TxIm.sendSystemAlert(toTengXunCode, content);
        }
    }
}
